package com.yeqian.user.security;

import com.yeqian.entity.ResultJson;
import com.yeqian.user.entity.LoginConstant;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.web.session.SessionInformationExpiredEvent;
import org.springframework.security.web.session.SessionInformationExpiredStrategy;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @author yeqian
 * @Classname 过期会话策略
 * @Description TODO
 * @Date 2021/5/8 16:46
 */
@Component
@Slf4j
public class YeqExpiredSessionStrategy implements SessionInformationExpiredStrategy {
    @Override
    public void onExpiredSessionDetected(SessionInformationExpiredEvent event) throws IOException {
        log.warn(LoginConstant.EXPIRED_SESSION_DETECTED);
        ResultJson result = ResultJson.error(4002, LoginConstant.EXPIRED_SESSION_DETECTED);
        ResultJson.writeJSON(event.getResponse(),result);
    }
}
